<template>
  <div class="login-container">
    <div class="lc-tit">
      <h4><slot name="dl">登录</slot></h4>
      <slot name="zs">
        <span
          ><slot name="p-login">手机验证登录</slot>
          <slot name="p-icon"><img src="./phone.png" alt=""/></slot
        ></span>
      </slot>
    </div>
    <div class="lc-content">
      <van-form @submit="onSubmit">
        <slot name="user">
          <van-field
            class="bk"
            v-model="username"
            name="用户名"
            placeholder="请输入手机号"
            :rules="[{ required: true, message: '手机号码不正确，请重新输入' }]"
        /></slot>
        <slot name="other"></slot>
        <slot name="psw">
          <van-field
            class="bk"
            v-model="password"
            type="password"
            name="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
        </slot>
        <slot name="re-psw"> </slot>
        <slot name="yzm">
          <van-field
            v-model="sms"
            center
            clearable
            placeholder="验证码"
            class="yzm"
          >
          </van-field>
          <slot name="yzm">
            <van-button type="primary" size="normal" class="fsyzm"
              >xyz</van-button
            >
            <span class="change">看不清换一张</span></slot
          >
        </slot>
        <slot name="ph-yzm"> </slot>
        <div class="auto-login">
          <slot name="agree-login">
            <van-checkbox
              v-model="checked"
              shape="square"
              checked-color="#f08200"
              class="at-check"
              >自动登录</van-checkbox
            >
            <a href="#">忘记密码?</a>
          </slot>
        </div>
        <slot name="lgzc"
          ><div class="btn">
            <span tag="span" @click="toLogin">会员注册</span>
            <router-link to="/login" tag="span">登录</router-link>
          </div></slot
        >

        <slot name="bt">
          <p class="ts">提示：未注册用户将直接注册成为礼拜五用户</p>
          <p class="cp">用合作网站登录</p>
          <div class="login-way">
            <img src="./wechat.png" alt="" />
            <img src="./qq.png" alt="" /></div
        ></slot>
      </van-form>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'loginContainer',
  data() {
    return {
      username: '',
      password: '',
      checked: false,
      sms: '',
    };
  },
  methods: {
    onSubmit(values) {
      console.log('submit', values);
      console.log('jk');
    },
    toLogin() {
      let obj = JSON.stringify({ phone: this.username, pwd: this.password });
      console.log(obj);
      axios({
        method: 'post',
        url: 'small/user/v1/register',
        data: obj,
        headers: {
          'Content-Type': 'application/json',
        },
      }).then((res) => {
        if (res.data.status == '0000') {
          localStorage.setItem('sessionId', res.data.result.sessionId);
          localStorage.setItem('userId', res.data.result.userId);
          alert('恭喜你注册成功');
          this.$router.replace('/');
        } else {
          alert('账号密码格式有误');
        }
      });
    },
  },
};
</script>

<style scoped>
.zs {
  cursor: pointer;
}
.login-container {
  width: 387px;
  height: 500px;
  background-color: #fff;
  padding: 30px 42px;
}
.login-container h4 {
  font-size: 24px;
  color: #666;
}
.lc-tit {
  display: flex;
  width: 100%;
  justify-content: space-between;
}
.lc-tit span {
  color: #498e3d;
  font-size: 16px;
}
.lc-tit img {
  vertical-align: -2px;
  margin-left: 5px;
}
::v-deep form div {
  padding: 0;
}
::v-deep input {
  height: 44px;
  border: 1px solid #d3d3d3;
  padding-left: 12px;
  margin-top: 20px;
}
::v-deep .yzm {
  width: 160px;
  display: inline-block;
}
::v-deep .fsyzm {
  width: 90px;
  margin-left: 30px;
  background-color: #498e3d;
  border: 0;
  transform: translateY(-22px);
}
span.change {
  color: #f08200;
  font-size: 14px;
  margin-left: 14px;
  vertical-align: 16px;
}
::v-deep.auto-login {
  display: flex;
  justify-content: space-between;
}
::v-deep.auto-login a {
  font-size: 14px;
  color: #f08200;
  text-decoration: underline;
}
::v-deep span.van-checkbox__label {
  color: #666;
  font-size: 14px;
}
.btn {
  display: flex;
  width: 100%;
  justify-content: space-between;
  margin-top: 20px;
}
.btn span {
  width: 133px;
  height: 46px;
  border-radius: 5px;
  color: #fff;
  text-align: center;
  line-height: 46px;
  font-size: 18px;
  cursor: pointer;
}
.btn span:nth-child(1) {
  background-color: #f08200;
}
.btn span:nth-child(2) {
  background-color: #498e3d;
}
.ts {
  text-align: center;
  margin: 14px auto;
  font-size: 14px;
  color: #999;
}
.cp {
  text-align: center;
  font-size: 16px;
  color: #666;
}
.login-way {
  text-align: center;
  margin-top: 14px;
}
.login-way img {
  cursor: pointer;
}
.login-way img:nth-child(1) {
  margin-right: 20px;
}
</style>
